
package Presentacion;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JFrame;


public class Image extends JComponent
{
    BufferedImage image;
    int x,y;
    
    public void paint(Graphics g)
    {
        g.drawImage(image, x, y, null);
    }
    
    public void setImage(String path)
    {
        try
        {
            image = ImageIO.read(new File(path));
        }
        catch(Exception e)
        {
            System.out.println("No se cargo la imagen: " + path);
        }
    }
    
    public Dimension getPreferredSize()
    {
        if(image == null)
        {
            return new Dimension(100,100);
        }
        return new Dimension(image.getWidth(), image.getHeight());
    }
   
    public Image(String path)
    {
        try
        {
            image = ImageIO.read(new File(path));
        }
        catch(Exception e)
        {
            System.out.println("No se cargo la imagen: " + path);
        }
    }
    public static void main(String[] args) {
        JFrame frame = new JFrame("Image");
        Image img = new Image("ahorcado6.png");
        frame.add(img);
        frame.pack();
        frame.setVisible(true);
    }
}
